package com.cybertron.am.wordpress.util;

import lombok.extern.slf4j.Slf4j;
import org.mvel2.MVEL;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;

@Slf4j
public class SysUtil {
    public static <T> T mvelEval(String expression, Map<String, Object> vars, Class<T> toType) {
        try {
            return MVEL.eval(expression, vars, toType);
        } catch (Throwable e) {
            log.debug("eval error", e);
            return null;
        }
    }

    public static String traceError(Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
}
